#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

ll a, c, p;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) { x = 1, y = 0; return a; };
    ll g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

ll inv(ll a, ll m)
{
    ll x, y;
    ll g = exgcd(a, m, x, y);
    return (x % m + m) % m;
}

void solve()
{
    cin >> a >> c >> p;
    ll ans = (p - 1) * inv(p - 1, p);
    cout << ans;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}